import {reqCateGoryList, reqGetBannerList, reqGetFloorList} from '@/api'

//home模块的小仓库
const state = {
    categoryList: [],           /*三级分类数据*/
    bannerList: [],             /*轮播图数据*/
    floorList: []              /*热卖floor数据*/
}
//mutation是唯一修改state的地方
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    BANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    FLOORLIST(state, floorList) {
        state.floorList = floorList
    }
}
const actions = {
    //获取三级分类数据
    async categoryList({commit}) {
        let result = await reqCateGoryList()
        if (result.code === 0) {
            commit("CATEGORYLIST", result.data)
        }
    },

    //获取首页轮播图的数据
    async getBannerList({commit}) {
        let result = await reqGetBannerList()
        if (result.code === 200) {
            commit("BANNERLIST", result.data)
        }
    },

    //获取floor数据
    async getFloorList({commit}) {
        let result = await reqGetFloorList()
        if (result.code === 200) {
            commit("FLOORLIST", result.data)
        }
    }
}
//计算属性
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters
}
